package com.payment.web.controller.system;

import java.util.List;

import com.payment.common.annotation.Log;
import com.payment.common.base.AjaxResult;
import com.payment.common.enums.BusinessType;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.common.utils.StringUtils;
import com.payment.framework.util.ShiroUtils;
import com.payment.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.system.domain.AppVersion;
import com.payment.system.service.IAppVersionService;


/**
 * app版本 信息操作处理
 * 
 * @author payment
 * @date 2019-01-14
 */
@Controller
@RequestMapping("/system/appVersion")
public class AppVersionController extends BaseController
{
    private String prefix = "system/appVersion";
	
	@Autowired
	private IAppVersionService appVersionService;
	
	@RequiresPermissions("system:appVersion:view")
	@GetMapping()
	public String appVersion()
	{
	    return prefix + "/appVersion";
	}
	
	/**
	 * 查询app版本列表
	 */
	@RequiresPermissions("system:appVersion:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AppVersion appVersion)
	{
		startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出app版本列表
	 */
	@RequiresPermissions("system:appVersion:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppVersion appVersion)
    {
    	List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        return util.exportExcel(list, "app版本");
    }
	
	/**
	 * 新增app版本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存app版本
	 */
	@RequiresPermissions("system:appVersion:add")
	@Log(title = "app版本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AppVersion appVersion)
	{
		appVersion.setUpdateUser(ShiroUtils.getLoginName());
		appVersion.setId(StringUtils.randomUUID());
		return toAjax(appVersionService.insertAppVersion(appVersion));
	}

	/**
	 * 修改app版本
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		AppVersion appVersion = appVersionService.selectAppVersionById(id);
		mmap.put("appVersion", appVersion);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存app版本
	 */
	@RequiresPermissions("system:appVersion:edit")
	@Log(title = "app版本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AppVersion appVersion)
	{		
		return toAjax(appVersionService.updateAppVersion(appVersion));
	}
	
	/**
	 * 删除app版本
	 */
	@RequiresPermissions("system:appVersion:remove")
	@Log(title = "app版本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(appVersionService.deleteAppVersionByIds(ids));
	}


	/**
	 * 	//修改启用 禁用状态
	 * @param id
	 * @param status
	 * @return
	 */
	@PostMapping("/updateStatusById")
	@ResponseBody
	public AjaxResult updateStatusById(String id,String status)
	{
		return appVersionService.updateStatusById(id,status);
	}


}
